<template>
	<view>
		<u-navbar leftText="返回" :safeAreaInsetTop="true" height="64px" safeAreaInsetTop="false">
			<view class="u-nav-slot" slot="left">
				<view style="display: flex;align-items: center;">
					<u-icon name="arrow-left" size="22" @click="back()"></u-icon>
					<view style="height: 20rpx;width: 25rpx;"></view>
					<u-search :showAction="false" v-model="param.tabName" :animation="false" @search="native()">
					</u-search>
				</view>
			</view>
		</u-navbar>
		<view style="margin-top: 210rpx;">
			<view class="goods_list">
				<view class="goods_item" v-for="item in urls" :key="item" @click="navigator(item)">
					<image :src="item" lazy-load="true" mode="aspectFill"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import detail from '../components/detail/detail.vue'
	import navbox from '../components/navbox/navbox.vue'
	export default {
		data() {
			return {
				timer: null,
				total: '',
				urls: [],
				param: {
					pageSize: 36,
					pageNum: 1,
					tabName: '',
					userId: uni.getStorageSync("user").id
				}
			}
		},
		onReachBottom() {
			this.getBottom()
		},
		onLoad() {
			if (this.timer) {
				clearTimeout(this.timer); // 清除定时器  
			}
		},
		components: {
			"navbox": navbox,
			"detail": detail
		},
		methods: {
			navigator(current) {
				uni.previewImage({
					current,
					urls: this.urls
				})
			},
			back() {
				uni.navigateBack()
			},
			async getBottom() {
				console.log(this.urls.length,this.total)
				const that = this
				if (this.urls.length < this.total) {
					this.param.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/wexinLogin/pictures/findpicbytab",
						method: 'POST',
						data: that.param,
						success(res) {
							that.urls = [...that.urls, ...res.data.data.data.records]
						}
					})
					this.timer = setTimeout(function() {
						uni.hideLoading();
					}, 800);
				}
			},
			async native() {
				uni.showLoading({
					title: '加载中'
				});
				const res = await this.$myRuquest({
					url: '/wexinLogin/pictures/findpicbytab',
					method: 'post',
					data: this.param
				})

				this.urls = res.data.data.data.records
				this.total=res.data.data.data.total
				uni.hideLoading();
			},

		}
	}
</script>

<style lang="scss" scoped>
	.goods_list {
		// padding: 0 15rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;


		.goods_item {
			background: #fff;
			width: 174rpx;
			padding: 5rpx;

			// box-sizing: border-box;
			image {
				width: 170rpx;
				height: 175rpx;
				display: block;
				margin: auto;
			}


			.price {
				color: $shop-color;
				font-size: 36rpx;
				margin: 20rpx 0 5rpx 0;

				text:nth-child(2) {
					color: #ccc;
					font-size: 28rpx;
					margin-left: 17rpx;
					text-decoration: line-through;
				}
			}

			.name {
				font-size: 28rpx;
				line-height: 50rpx;
				padding-bottom: 15rpx;
				padding-top: 10rpx;
			}
		}
	}
</style>
